package testProxy;

import testProxy.cglib.CglibDynamicProxy;
import testProxy.javassist.Javassist;
import testProxy.javassistcode.JavassistCode;
import testProxy.jdk.JDKDynamicProxyHandler;

public class ProxyTest {
	private static void Tuning(int type) throws Throwable{
	    IDBQuery proxy=null;
	    long start=System.currentTimeMillis();
	    String typeName="";
	    
	    switch(type){
//	    case 1:
//	      proxy=new DBQueryProxy();
//	      typeName="Proxy";
//	      break;
	    case 2:
	      proxy=JDKDynamicProxyHandler.createDynamicProxy();
	      typeName="JDKProxy";
	      break;
	    case 3:
	      proxy=CglibDynamicProxy.createDynamicProxy();
	      typeName="CglibProxy";
	      break;
	    case 4:
	      proxy=Javassist.createJavassistProxy();
	      typeName="JavassistProxy";
	      break;
	    case 5:
	        proxy=JavassistCode.createJavassistBytecodeProxy();
	        typeName="JavassistProxy";
	      break;
	    }
	    long end=System.currentTimeMillis();
	    System.out.println(typeName+" created: "+(end-start));
	    System.out.println(proxy.getClass().getName());
	    
	    start=end;
	    //执行3千万次，看看执行的时间是多少
	    for(int i=0;i<30000000;i++)
	      proxy.request();
	    
	    end=System.currentTimeMillis();
	    System.out.println("Call "+typeName+" request(): "+(end-start));
	    System.out.println("");
	  }
	  /**
	   * @param args
	   */
	  public static void main(String[] args) throws Throwable {
//	    Tuning(1);
	    Tuning(2);
	    Tuning(3);
	    Tuning(4);
	    Tuning(5);
	  }
}
